<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link rel="stylesheet" href="/css/elementUI.css">
    <script src="/js/vue.js"></script>
    <script src="/js/axios.js"></script>
    <script src="/js/elementUI.js"></script>
</head>
<body>


<div id="app">

    工号：<el-input v-model="emp.worknum" style="width: 200px" placeholder="请输入工号" clearable></el-input>
    <br>
    密码：<el-input v-model="emp.idcard" style="width: 200px" placeholder="请输入身份证后六位登录" show-password  clearable></el-input>
    <br>
    <el-button type="primary" @click="toLogin">登录</el-button>

</div>
<script>
    new Vue({
        el:"#app",
        data:{
            emp:{
                worknum:"",
                idcard:""
            }
        },
        watch:{
        },
        methods:{
            toLogin(){
                axios.post("/emp/login",this.emp).then(res=>{
                    //登录成功返回emp对象，不成功，返回字符串
                    if(res.data.id){
                        let emp = res.data;
                        localStorage.setItem("userInfo",JSON.stringify(emp));
                        if(emp.type=="人资"){
                            location.href = "empAdmin.html";
                        }else if(emp.type=="普通员工"){
                            location.href = "daka.html";
                        }
                    }else{
                        this.$message.error(res.data)
                    }

                })
            },
            initData(){

            }

        },
        created(){
            this.initData()
        }
    })
</script>

</body>
</html>